package com.bitongchong.test;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;


/*
 * 思路：
 * 输入一个数，先对数进行处理，分成用户名和时间字符串，存入hash表中
 * 字符串处理成链表形式（先判断是否存在这个用户，如果存在就直接让链表
 * 的next指向新字符串，如果不存在，就直接将用户存入hash表中，并且
 * 创建一个新的链表存数据
 * 遍历hash表，对每个key都判断一次，判断一小时的间隔之内有6个值（
 * 实现：利用滑动窗口算法），
 * 如果有，存到一个表中，写一个比较器，输出按字典序排列的结果
 */

public class Code_03_OJ {
	
	public static class Node {
		public Long value;
		public Node next;

		public Node(Long data) {
			this.value = data;
		}
	}

	public static Node resFound(HashMap<String, Node> map) {
		Node resNode = null;
		Iterator<String> iterator = map.keySet().iterator();
		while(iterator.hasNext()) {
			String key = iterator.next();
			Node curNode = map.get(key);
			curNode = nodeSort(curNode);
			if (countJudge(curNode)) {
				if (resNode != null) {
					Node curNode2 = resNode;
					while(curNode2.next != null) {
						curNode2 = curNode2.next;
					}
					curNode2.next = new Node(Long.valueOf(key));
				}else {
					resNode = new Node(Long.valueOf(key));
				} 
 			}
		}
		return resNode;
	} 
	
	public static Boolean countJudge(Node curNode) {
		Node startNode = curNode;
		Node endNode = curNode;
		Boolean res = false;
		int n = 1;
		endNode = endNode.next;
		if (endNode == null) {
			return res;
		}else {
			while(endNode != null) {
				if (endNode.value - startNode.value > 3600000) {
					startNode = startNode.next;
					n--;
				}else {
					n++;
					if (n >= 6) {
						res = true;
						break;
					}
				}
				endNode = endNode.next;
			}
		}
		return res;
	}
	
	public static long dateString2Long(String inVal) {
		Date date = null;
		SimpleDateFormat inputFormat = new SimpleDateFormat("hh:mm:ss");
		try {
			date = inputFormat.parse(inVal);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return date.getTime();
	}
	
	public static Node nodeSort(Node head) {
		Long num = head.value;
		Node smaller = null;
		Node bigger = null;
		Node equal = null;
		Node smallerEnd = null;
		Node biggerEnd = null;
		Node equalEnd = null;
		while(head != null) {
			if (head.value > num) {
				if (biggerEnd == null) {
					biggerEnd = head;
					bigger = head;
				}else {
					biggerEnd.next = head;
					biggerEnd = head;
				}
			}else if (head.value == num) {
				if (equalEnd == null) {
					equal = head;
					equalEnd = head;
				}else {
					equalEnd.next = head;
					equalEnd = head;
				}
			}else {
				if (smallerEnd == null) {
					smaller = head;
					smallerEnd = head;
				}else {
					smallerEnd.next = head;
					smallerEnd = head;
				}
			}
			head = head.next;
		}
		if (smaller != null && equal != null) {
			smallerEnd.next = equal;
			equalEnd.next = bigger;
			return smaller;
		}else if (smaller != null) {
			smallerEnd.next = bigger;
			return smaller;
		}else if(equal != null){
			equalEnd.next = bigger;
			return equal;
		}else {
			return bigger;
		}
	}
	
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Long time = null;
		Scanner scanner = new Scanner(System.in);
		HashMap<String, Node> map = new HashMap<>();
		int i = Integer.parseInt(scanner.nextLine());
		for (int j = 0; j < i; j++) {
			String string = scanner.nextLine();
			String[] strings = string.split(" ");
			if (string.charAt(0) == 's') {
				strings[0] = strings[0].substring(1, strings[0].length());
				time = dateString2Long(strings[1]);
				if (map.containsKey(strings[0])) {
					Node curNode = map.get(strings[0]);
					while(curNode.next != null) {
						curNode = curNode.next;
					}
					curNode.next = new Node(time);
				}else {
					map.put(strings[0], new Node(time));
				}
			}
		}
		Node resNode = resFound(map);
		resNode = nodeSort(resNode);
		while(resNode != null) {
			System.out.println("s"+resNode.value);
			resNode = resNode.next;
		}
	}
}
